package com.codefactory.ui;

import org.apache.commons.lang3.time.DateFormatUtils;

import javax.swing.*;
import java.awt.*;
import java.util.Date;

public class FactoryWindow {

    static final int BTN_WIDTH = 93;
    static final int TEXT_WIDTH = 250;
    static final int LBL_WIDTH = 70;
    static final int BTN_HEIGHT = 30;

    // 定义一个JFrame对象，表示应用程序的主窗口
    private JFrame frame;
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    private JTextField textField_4;

    private Font lblFont = new Font("宋体", Font.BOLD, 16);
    private Font textFont = new Font("宋体", Font.BOLD, 16);
    private Font btnFont = new Font("宋体", Font.BOLD, 18);

    // 应用程序的入口点
    public static void main(String[] args) {
        // 使用事件队列在UI线程上异步执行代码
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    // 创建FactoryWindow对象
                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                    FactoryWindow window = new FactoryWindow();
                    // 设置窗口为可见状态
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    // 构造方法，用于创建应用程序的主窗口
    public FactoryWindow() {
        // 初始化窗口的内容
        initialize();
    }

    // 初始化窗口的内容
    private void initialize() {
        // 创建一个新的JFrame对象，表示应用程序的主窗口
        frame = new JFrame();
        frame.setTitle("FactoryWindow");
        // 设置窗口的位置和大小
        frame.setBounds(100, 100, 775, 460);
        frame.setLocationRelativeTo(null);// 显示屏幕中间,写在设置窗体大小的后面
        // 设置窗口关闭时的默认操作（退出应用程序）
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // 设置标题栏图标
        frame.setIconImage(new ImageIcon(FactoryWindow.class.getClassLoader().getResource("cmder.png")).getImage());

        frame.getContentPane().setLayout(null);

        textField = new JTextField();
        textField.setFont(textFont);
        textField.setBounds(97, 20, TEXT_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(textField);
        textField.setColumns(10);

        textField_1 = new JTextField();
        textField_1.setFont(textFont);
        textField_1.setBounds(453, 20, TEXT_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(textField_1);
        textField_1.setColumns(10);

        textField_2 = new JTextField();
        textField_2.setFont(textFont);
        textField_2.setBounds(97, 81, TEXT_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(textField_2);
        textField_2.setColumns(10);

        textField_3 = new JTextField();
        textField_3.setFont(textFont);
        String now = DateFormatUtils.format(new Date(), "yyyy/MM/dd");
        textField_3.setText(now);
        textField_3.setBounds(453, 81, TEXT_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(textField_3);
        textField_3.setColumns(10);

        textField_4 = new JTextField();
        textField_4.setFont(textFont);
        textField_4.setBounds(97, 134, TEXT_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(textField_4);
        textField_4.setColumns(10);

        JComboBox comboBox = new JComboBox();
        comboBox.setFont(new Font("宋体", Font.BOLD, 18));
        comboBox.setModel(new DefaultComboBoxModel(new String[]{"backend_templates", "swing_templates"}));
        comboBox.setBounds(453, 133, TEXT_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(comboBox);

        JLabel lblNewLabel = new JLabel("项目包名");
        lblNewLabel.setFont(lblFont);
        lblNewLabel.setBounds(22, 20, LBL_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(lblNewLabel);

        JLabel lblNewLabel_1 = new JLabel("模块包");
        lblNewLabel_1.setFont(lblFont);
        lblNewLabel_1.setBounds(373, 20, LBL_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(lblNewLabel_1);

        JLabel lblNewLabel_2 = new JLabel("作者");
        lblNewLabel_2.setFont(lblFont);
        lblNewLabel_2.setBounds(22, 81, LBL_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(lblNewLabel_2);

        JLabel lblNewLabel_3 = new JLabel("日期");
        lblNewLabel_3.setFont(lblFont);
        lblNewLabel_3.setBounds(373, 81, LBL_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(lblNewLabel_3);

        JLabel lblNewLabel_4 = new JLabel("模块名");
        lblNewLabel_4.setFont(lblFont);
        lblNewLabel_4.setBounds(22, 134, LBL_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(lblNewLabel_4);

        JLabel lblNewLabel_5 = new JLabel("模板类型");
        lblNewLabel_5.setFont(lblFont);
        lblNewLabel_5.setBounds(373, 134, LBL_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(lblNewLabel_5);

        JButton btnNewButton = new JButton("查询表");
        btnNewButton.setFont(btnFont);
        btnNewButton.setBounds(22, 205, BTN_WIDTH, BTN_HEIGHT);
        frame.getContentPane().add(btnNewButton);
    }
}
